package api

import (
	_ "newsletter-subs/docs"
	"newsletter-subs/pkg/util"

	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

var RouteEng *gin.Engine

func InitServer() {
	RouteEng = gin.Default()

	// Add security definitions to Swagger docs
	url := ginSwagger.URL("doc.json") // The url pointing to API definition
	RouteEng.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))

	RegistRouteSubscriptions()
	if err := RouteEng.Run(); err != nil {
		util.Logger.Fatalln("newsletter-subs start failed!")
	} else {
		util.Logger.Println("newsletter-subs start success!")
	}
}
